@isTest
// this is a placeholder test class only
private class CaseEmailsComponentTest {
    
  static testMethod void testTextEmailMessage()
    {    	

		Case testCase = new Case(Description='Test Case');
		insert testCase;
		    	
		EmailMessage testMessage = new EmailMessage();
     	testMessage.TextBody    = 'test email from test method!';
     	testMessage.FromAddress = 'testFrom@att.com';
     	testMessage.ToAddress   = 'testTo@att.com';
     	testMessage.MessageDate = System.today();    
     	testMessage.ParentId    = testCase.Id;
        insert testMessage;
        
    	
    	CaseEmailsComponentController caseEmail = new CaseEmailsComponentController();
    	caseEmail.emailCase = testCase;
    	
    	List<CaseEmailsComponentController.cEmail> messages =  caseEmail.getCaseEmailMessage();
    	
    	System.assertEquals(messages[0].Body, 'test email from test method!');
    	//System.Assert(messages[0].Body == 'test email from test method!');
    	
    }
   static testMethod void testHTMLEmailMessage()
    {    	

		Case testCase = new Case(Description='Test Case');
		insert testCase;
		    	
		EmailMessage testMessage = new EmailMessage();
		//insert the htmlbody
     	testMessage.HtmlBody    = '<html>test email from test method!</html>';
     	testMessage.FromAddress = 'testFrom@att.com';
     	testMessage.ToAddress   = 'testTo@att.com';
     	testMessage.MessageDate = System.today();    
     	testMessage.ParentId    = testCase.Id;
        insert testMessage;
        
    	
    	CaseEmailsComponentController caseEmail = new CaseEmailsComponentController();
    	caseEmail.emailCase = testCase;
    	
    	List<CaseEmailsComponentController.cEmail> messages =  caseEmail.getCaseEmailMessage();
    	
    	System.assertEquals(messages[0].Body, '<html>test email from test method!</html>');
    	//System.Assert(messages[0].Body == 'test email from test method!');
        	
    }
    
   static testMethod void testDeleteEmailMessage()
    {    	
		Case testCase = new Case(Description='Test Case');
		insert testCase;
		    	
		EmailMessage testMessage = new EmailMessage();
		//insert the htmlbody
     	testMessage.HtmlBody    = '<html>test email from test method!</html>';
     	testMessage.FromAddress = 'testFrom@att.com';
     	testMessage.ToAddress   = 'testTo@att.com';
     	testMessage.MessageDate = System.today();    
     	testMessage.ParentId    = testCase.Id;
        insert testMessage;
        
    	
    	CaseEmailsComponentController caseEmail = new CaseEmailsComponentController();
    	caseEmail.emailId= testMessage.Id;
		//test condition    	
    	caseEmail.deleteEmailMessage();
    	try    	
    	{
        	EmailMessage deletedMessage =  [select id from EmailMessage where id = :testMessage.Id];
    	} 
    	catch (QueryException e)  	{    		
    		//Assert Error Message
		    System.assert( e.getMessage().contains('List has no rows for assignment to SObject'), e.getMessage() ); 
    	}
        
        
    }   
     static testMethod void testViewDatawithHTMLBody()
    {    	

		Case testCase = new Case(Description='Test Case');
		insert testCase;
		    	
		EmailMessage testMessage = new EmailMessage();
		//insert the htmlbody
     	testMessage.HtmlBody    = '<html>test email from test method!</html>';
     	testMessage.FromAddress = 'testfrom@att.com';
     	testMessage.ToAddress   = 'testto@att.com';
     	testMessage.MessageDate = System.today();    
     	testMessage.ParentId    = testCase.Id;
        insert testMessage;
        
    	ApexPages.PageReference ref = new PageReference('/apex/EmailMessageDetail?id='+testMessage.Id );
    	test.setCurrentPageReference(ref);
    	
    	CaseEmailsComponentController testEmail = new CaseEmailsComponentController();
    	    	
    	testEmail.ViewData();
    	
    	System.assertEquals('<html>test email from test method!</html>',testEmail.getcaseEmail().Body);
    	//check other columns 
    	System.assertEquals('testfrom@att.com', testEmail.getcaseEmail().FromAddress );
    	System.assertEquals('testto@att.com', testEmail.getcaseEmail().ToAddress);
    	
        	
    }
      static testMethod void testViewDatawithTextBody()
    {    	

		Case testCase = new Case(Description='Test Case');
		insert testCase;
		    	
		EmailMessage testMessage = new EmailMessage();
		//insert the htmlbody
     	testMessage.TextBody    = 'test email from test method!';
     	testMessage.FromAddress = 'testfrom@att.com';
     	testMessage.ToAddress   = 'testto@att.com';
     	testMessage.MessageDate = System.today();    
     	testMessage.ParentId    = testCase.Id;
        insert testMessage;
        
    	ApexPages.PageReference ref = new PageReference('/apex/EmailMessageDetail?id='+testMessage.Id );
    	test.setCurrentPageReference(ref);
    	
    	CaseEmailsComponentController testEmail = new CaseEmailsComponentController();
    	    	
    	testEmail.ViewData();
    	
    	System.assertEquals('test email from test method!', testEmail.getcaseEmail().Body);
    	//check other columns 
    	System.assertEquals('testfrom@att.com', testEmail.getcaseEmail().FromAddress );
    	System.assertEquals('testto@att.com', testEmail.getcaseEmail().ToAddress);
    	
        	
    }  
}